package com.weijin.web.controller;

import com.weijin.model.ChatHistory;
import com.weijin.service.IChatHistoryService;
import com.weijin.vo.PageVo;
import com.weijin.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/20 15:18
 */
@RestController
@RequestMapping("/chatHistory")
@Api(tags = "聊天记录相关接口")
public class ChatHistoryController {

    @Resource
    private IChatHistoryService chatHistoryService;

    @PostMapping("/add")
    @ApiOperation("添加聊天记录")
    public RestResultVo<ChatHistory> addChatHistory(@RequestBody ChatHistory chatHistory) {
        ChatHistory dataChatHistory = chatHistoryService.addChatHistory(chatHistory);
        return RestResultVo.ok(dataChatHistory);
    }

    @GetMapping("/page")
    @ApiOperation("分页获取历史聊天记录")
    public RestResultVo<PageVo<ChatHistory>> pageChatHistory(
            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "50") Integer pageSize) {
        PageVo<ChatHistory> pageVo = chatHistoryService.pageChatHistory(pageNumber, pageSize);
        return RestResultVo.ok(pageVo);
    }
}
